<?php
//PingBuWang.Com
//Copyright (c) 2017~2099 http://www.pingbuwang.com All rights reserved.
namespace app\index\controller;
use mip\ApiBase;
use mip\AuthApiBase;
use think\Request;
use think\Response;
use think\Session;
use mip\Mip;
use com\Network;
use app\common\controller\Common;
use WeMini;

class ApiUserWxmini extends ApiBase
{

    public function login(){
        $config = [
            'appid'     => 'wxabf24a4f9bf80503',
            'appsecret' => '16b7a61d65fffbc3187db36d1947ea9f',
        ];
        $mini = new WeMini\Crypt($config);
        $code = input('code');

        $arr = $mini->session($code);

        if($arr['errcode'] === 0) {
            return jsonSuccess('用户登录成功', $arr);
        }else{
            return jsonError('用户登录出现了异常',$arr);
        }
    }

    public function decode(){
        $config = [
            'appid'     => 'wxabf24a4f9bf80503',
            'appsecret' => '16b7a61d65fffbc3187db36d1947ea9f',
        ];

        $iv = input('iv');
        $encryptedData = input('encryptedData');
        $sessionKey = input('sessionKey');

        $mini = new WeMini\Crypt($config);

        $res = $mini->decode(iv,sessionKey,encryptedData);

        return jsonSuccess('解密完成',$res);
    }


}
